class AcessoFilters {
    def authenticateService
    def filters = {
 
        loginCheck(controller:'login' , invert:true) {
            before = {                  
              if (!params.controller || params.controller == 'incricaoCadastroPass' || (params.controller == 'inscricao'  &&  params.action !='create' && params.action !='enviarEmail' && params.action !='save' && params.action !='confirmacao' && params.action !='save'   && params.action != 'validacao'  && params.action != 'aviso')) {
                def login = authenticateService.principal()
              
                if (login == 'anonymousUser') {                     

                 if (params.valor) {                       
                 } else {
                      redirect(controller:"login",action:"auth")
                 }
                    } else {
                        def user =  Inscricao.findByUsuario(Usuario.findByUsername(login.getUsername()))
                        def admin = true
                        login.getAuthorities().each{
                       if ( it == "ROLE_USER" ) {
                              admin = false
                                }
                       if (admin == false && params.action != 'status' ) {
                           redirect(controller:"inscricao",action:"status", "id": user.id)
                       }
                        }
                }
                }


            }


        }

       
    }

}



